package com.ynby.newyp.controller;

import com.ynby.newyp.pojo.ArrPojo;
import com.ynby.newyp.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class IndexController {
    @Autowired
    IndexService indexService;

    @RequestMapping("indexPage.do")
    public String indexPage(HttpServletRequest request){
        HttpSession session=request.getSession();
        if(session.getAttribute("flag")==null){
           return "page-login";
        }
        return "index";
    }

    @RequestMapping("query.do")
    @ResponseBody
    public List<ArrPojo> query(ArrPojo arrPojo)
    {
        System.out.println("asd");
        return indexService.query(arrPojo);
    }

    @RequestMapping("index.do")
    @ResponseBody
    public String add(ArrPojo arrPojo){
        if ("".equals(arrPojo.getPnum())||arrPojo.getPnum()==null){
            return "请输入偏差编号";
        }
        return indexService.add(arrPojo);
    }


}
